import {UserProfilesAPI} from '@/request/api'
export default {
    namespaced: true,
    state: {
        //购物车数量
        cartTotal: 100,
        //用户信息
        userInfo:
        {
            //昵称
            nickName: "昵称",
            //积分
            coin: 1000,
            //用户头像
            headimg: require('../../assets/img/service.848ec511.png')
        }

    },
    getters: {

    },
    mutations: {
        updateUserInfo(state,payload){
            state.cartTotal=payload.cartTotal;
            state.userInfo=payload.userInfo
        },
        initUserInfo(state){
            state.cartTotal=0;
            state.userInfo={
                nickName:'昵称',
                coin:1000,
                headImg:require("../../assets/img/service.848ec511.png")
            }
        }

    },
    actions: {
        async asyncChangeUserInfo({commit},payload){
            let res=await UserProfilesAPI()
            commit("updateUserInfo",res.data)
        }
    },
}